package com.boonya.springcloud.utils;

import java.util.WeakHashMap;

/**
 * @ClassName: SimpleCache
 * @Description: TODO(WeakHashMap实现的HashMap缓存方法)
 * @author: pengjunlin
 * @motto: 学习需要毅力，那就秀毅力
 * @date 2021/4/23 11:37
 */
public class SimpleCache {

    /**
     * 被垃圾回收器回收缓存对象
     */
    private static WeakHashMap<String, Object> weakHashMap = new WeakHashMap<>(100000);

    public static Object get(String key) {
        if(weakHashMap.containsKey(key)){
            return weakHashMap.get(key);
        }
        return null;
    }

    public static void put(String key, String value) {
        weakHashMap.put(key, value);
    }

    public static void del(String key) {
        if(weakHashMap.containsKey(key)){
            weakHashMap.remove(key);
        }
    }
}
